import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {
			id:'',
			userName:'',
			jwt:'',
			avatar:'',
			address:'',
			email:'',
			integral:null,
			password:null,
			phone:'',
			role:0
		},
	},
	mutations: {
		login(state, provider) {

			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({//缓存用户登陆状态
			    key: 'userInfo',  
			    data: provider  
			}) 
			console.log(state.userInfo);
		},
		logout(state) { 
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({  
                key: 'userInfo'  
            })
		},
		setAvatar(state, avatar) {
		
			state.userInfo.avatar = avatar;
			uni.setStorage({
			    key: 'userInfo.avatar',  
			    data: avatar  ,
				success() {
					console.log('success')
				}
			}) 
			console.log(state.userInfo);
		}
	},
	actions: {
	
	}
})

export default store
